export default{
	state:{
		//登录状态
		loginStatus:false,
		//token
		token:null,
		//用户信息(昵称/头像)
		userInfo:{},
		device_id:null,
		number_times:null,
		cardData: uni.getStorageSync('card') || []
	},
	getters:{
	  getCard: (state) => {
		return uni.getStorageSync('card')
	  }
	},
	mutations:{
		setCard(state,card){
		  uni.setStorageSync('card', card)
		},
		//一旦进入了app，就需要执行这个方法，把用户信息读出来
		initUser(state){
      console.log('6515456454564564564')
			let device_id = uni.getStorageSync('device_id');
			let userInfo = uni.getStorageSync('userInfo');
			let token = uni.getStorageSync('token');
			if(token){
				state.token = token;
			}
			if(device_id){
				state.device_id = device_id;
			}
			if( userInfo ){
				userInfo = JSON.parse( userInfo );
				state.userInfo = userInfo;
				state.loginStatus = true;
				state.number_times =userInfo.number_times;
				//state.token = userInfo.token;
			}
		},
		//登录后保存用户信息
		login(state,userInfo){
			state.userInfo = userInfo;
			state.loginStatus = true;
			state.number_times = userInfo.number_times;
			//state.token = userInfo.token;
			//持久化存储 ===>把对象转换成字符串
			uni.setStorageSync('userInfo',JSON.stringify(userInfo))
			uni.setStorageSync('number_times', JSON.stringify(userInfo.number_times));
		},

	},
	actions:{}
}
